clear all;

load finalDataSet.mat

disp("Column 1 of Table 6")
F = finalDataSet; 
    T = F( F(:,4)==1,:);
    C = F( F(:,4)==0,:);
    
    disp("Change in Depth")
    
    variableT = T(:,13) - T(:,8); 
    variableC = C(:,13) - C(:,8);
    
    diff = mean(variableT) - mean(variableC)
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue (%)")
    variableT = T(:,6).*T(:,16) - T(:,5).*T(:,11); 
    variableC = C(:,6).*C(:,16) - C(:,5).*C(:,11);
    
    % Percentage difference 
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,5).*F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue per Search (%)")
    
    variableT = T(:,16) - T(:,11); 
    variableC = C(:,16) - C(:,11);
    
    % Percentage difference
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')

    disp("Numbers of observations")
    [size(T,1); size(C,1)]

    disp("Fraction of total revenue (%)")
    100*sum(F(:,5).*F(:,11))/sum(finalDataSet(:,5).*finalDataSet(:,11))   

disp("Column 2 of Table 6")
F = finalDataSet(finalDataSet(:,5) < 300,:); 
    T = F( F(:,4)==1,:);
    C = F( F(:,4)==0,:);
    
    disp("Change in Depth")
    
    variableT = T(:,13) - T(:,8); 
    variableC = C(:,13) - C(:,8);
    
    diff = mean(variableT) - mean(variableC)
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue (%)")
    variableT = T(:,6).*T(:,16) - T(:,5).*T(:,11); 
    variableC = C(:,6).*C(:,16) - C(:,5).*C(:,11);
    
    % Percentage difference 
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,5).*F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue per Search (%)")
    
    variableT = T(:,16) - T(:,11); 
    variableC = C(:,16) - C(:,11);
    
    % Percentage difference
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')

    disp("Numbers of observations")
    [size(T,1); size(C,1)]

    disp("Fraction of total revenue (%)")
    100*sum(F(:,5).*F(:,11))/sum(finalDataSet(:,5).*finalDataSet(:,11))   

disp("Column 3 of Table 6/Column 1 of Table 7")
F = finalDataSet (finalDataSet(:,5) >= 300,:); 
    T = F( F(:,4)==1,:);
    C = F( F(:,4)==0,:);
    
    disp("Change in Depth")
    
    variableT = T(:,13) - T(:,8); 
    variableC = C(:,13) - C(:,8);
    
    diff = mean(variableT) - mean(variableC)
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue (%)")
    variableT = T(:,6).*T(:,16) - T(:,5).*T(:,11); 
    variableC = C(:,6).*C(:,16) - C(:,5).*C(:,11);
    
    % Percentage difference 
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,5).*F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue per Search (%)")
    
    variableT = T(:,16) - T(:,11); 
    variableC = C(:,16) - C(:,11);
    
    % Percentage difference
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')

    disp("Numbers of observations")
    [size(T,1); size(C,1)]

    disp("Fraction of total revenue (%)")
    100*sum(F(:,5).*F(:,11))/sum(finalDataSet(:,5).*finalDataSet(:,11))   

disp("Column 2 of Table 7")
F = finalDataSet (and(finalDataSet(:,5) >= 300,finalDataSet(:,12) < 0.2),:); 
    T = F( F(:,4)==1,:);
    C = F( F(:,4)==0,:);
    
    disp("Change in Depth")
    
    variableT = T(:,13) - T(:,8); 
    variableC = C(:,13) - C(:,8);
    
    diff = mean(variableT) - mean(variableC)
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue (%)")
    variableT = T(:,6).*T(:,16) - T(:,5).*T(:,11); 
    variableC = C(:,6).*C(:,16) - C(:,5).*C(:,11);
    
    % Percentage difference 
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,5).*F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue per Search (%)")
    
    variableT = T(:,16) - T(:,11); 
    variableC = C(:,16) - C(:,11);
    
    % Percentage difference
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')

    disp("Numbers of observations")
    [size(T,1); size(C,1)]

    disp("Fraction of total revenue (%)")
    100*sum(F(:,5).*F(:,11))/sum(finalDataSet(:,5).*finalDataSet(:,11))   

disp("Column 3 of Table 7/Column 1 of Table 8")
F = finalDataSet (and(finalDataSet(:,5) >= 300,finalDataSet(:,12) >= 0.2),:); 
    T = F( F(:,4)==1,:);
    C = F( F(:,4)==0,:);
    
    disp("Change in Depth")
    
    variableT = T(:,13) - T(:,8); 
    variableC = C(:,13) - C(:,8);
    
    diff = mean(variableT) - mean(variableC)
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue (%)")
    variableT = T(:,6).*T(:,16) - T(:,5).*T(:,11); 
    variableC = C(:,6).*C(:,16) - C(:,5).*C(:,11);
    
    % Percentage difference 
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,5).*F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue per Search (%)")
    
    variableT = T(:,16) - T(:,11); 
    variableC = C(:,16) - C(:,11);
    
    % Percentage difference
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')

    disp("Numbers of observations")
    [size(T,1); size(C,1)]

    disp("Fraction of total revenue (%)")
    100*sum(F(:,5).*F(:,11))/sum(finalDataSet(:,5).*finalDataSet(:,11))   

disp("Column 2 of Table 8")
F = finalDataSet (and(and(finalDataSet(:,5) >= 300,finalDataSet(:,12) >= 0.2),finalDataSet(:,8) < 5.5),:); 
    T = F( F(:,4)==1,:);
    C = F( F(:,4)==0,:);
    
    disp("Change in Depth")
    
    variableT = T(:,13) - T(:,8); 
    variableC = C(:,13) - C(:,8);
    
    diff = mean(variableT) - mean(variableC)
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue (%)")
    variableT = T(:,6).*T(:,16) - T(:,5).*T(:,11); 
    variableC = C(:,6).*C(:,16) - C(:,5).*C(:,11);
    
    % Percentage difference 
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,5).*F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue per Search (%)")
    
    variableT = T(:,16) - T(:,11); 
    variableC = C(:,16) - C(:,11);
    
    % Percentage difference
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')

    disp("Numbers of observations")
    [size(T,1); size(C,1)]

    disp("Fraction of total revenue (%)")
    100*sum(F(:,5).*F(:,11))/sum(finalDataSet(:,5).*finalDataSet(:,11))   

disp("Column 3 of Table 8")
F = finalDataSet (and(and(finalDataSet(:,5) >= 300,finalDataSet(:,12) >= 0.2),finalDataSet(:,8) >= 5.5),:); 
    T = F( F(:,4)==1,:);
    C = F( F(:,4)==0,:);
    
    disp("Change in Depth")
    
    variableT = T(:,13) - T(:,8); 
    variableC = C(:,13) - C(:,8);
    
    diff = mean(variableT) - mean(variableC)
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue (%)")
    variableT = T(:,6).*T(:,16) - T(:,5).*T(:,11); 
    variableC = C(:,6).*C(:,16) - C(:,5).*C(:,11);
    
    % Percentage difference 
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,5).*F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')
    
    disp("Change in Revenue per Search (%)")
    
    variableT = T(:,16) - T(:,11); 
    variableC = C(:,16) - C(:,11);
    
    % Percentage difference
    diff = 100*(mean(variableT) - mean(variableC))/mean(F(:,11))
    [~,p,~,stats] = ttest2(variableT,variableC,'Vartype','unequal')

    disp("Numbers of observations")
    [size(T,1); size(C,1)]

    disp("Fraction of total revenue (%)")
    100*sum(F(:,5).*F(:,11))/sum(finalDataSet(:,5).*finalDataSet(:,11))   
